package com.fs.cv.service.impl;

import com.fs.cv.dao.StudentInfoDao;
import com.fs.cv.pojo.pojodao.Class;
import com.fs.cv.pojo.pojodao.Student;
import com.fs.cv.pojo.pojodao.User;
import com.fs.cv.pojo.pojoview.StudentClassDepartment;
import com.fs.cv.pojo.pojoview.StudentInfo;
import com.fs.cv.service.StudentInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @工程名: SSM项目
 * @描述：
 * @作者: 小梁子
 * @创建时间: 2020-09-29 16:07
 **/

@Service
public class StudentInfoServiceImp implements StudentInfoService {
    //自动装配
    @Autowired
    StudentInfoDao studentInfoDao;

    //获取所有学生信息
    @Override
    public List<Student> getAllInfo() {
        List<Student> students=studentInfoDao.getAllInfo();
        return students;
    }
    //根据当前用户对应的班主任查询当前班级
    @Override
    public PageInfo<StudentInfo> getStudentInfoByUserId(Integer currentPage, Integer pageSize) {
        //获取当前登录的user
        Session session = SecurityUtils.getSubject().getSession();
        User user = (User) session.getAttribute("user");
        int userId=user.getUserId();
        //拦截查询
        PageHelper.startPage(currentPage,pageSize);
        List<StudentInfo> studentInfoByUserId = studentInfoDao.getStudentInfoByUserId(userId);
        PageInfo<StudentInfo> PageInfo = new PageInfo<>(studentInfoByUserId);
        return  PageInfo;
    }

    //增加一个学生的信息
    @Override
    public int addUserInfo(StudentInfo studentInfo) {
        return studentInfoDao.adduserInfo(studentInfo);
    }
    //通过用户ID查询班主任对应的Class
    @Override
    public Class getClassIdByUserId(Integer userId) {
        return studentInfoDao.getClassIdByUserId(userId);
    }

    //通过学号查询该生信息
    @Override
    public Student getOneStudentInfoById(Integer studentId) {
        return studentInfoDao.getOneStudentInfoById(studentId);
    }

    @Override
    public Integer editStudentInfo(Student student) {
        return studentInfoDao.editStudentInfo(student);
    }

    @Override
    public Integer deletedOneStudent(Integer studentId) {
        return studentInfoDao.deletedOneStudent(studentId);
    }

}
